package io.renren.controller;

import io.renren.annotation.LoginUser;
import io.renren.common.utils.Result;
import io.renren.dto.TemporaryOrderDTO;
import io.renren.entity.UserEntity;
import io.renren.service.TemporaryOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;


/**
 * 临时采购表
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-12-31
 */
@RestController
@RequestMapping("api/temporaryorder")
@Api(tags="临时采购表")
public class TemporaryOrderController {
    @Autowired
    private TemporaryOrderService temporaryOrderService;

    @GetMapping("getTemOrder")
    @ApiOperation("查询当前临时表是否存在")
    public Result<TemporaryOrderDTO> page(int sign , @LoginUser UserEntity entity){
        TemporaryOrderDTO temOrder = temporaryOrderService.getTemOrder(sign, entity.getId(), entity.getDeptId());
        //TemporaryOrderDTO temOrder = temporaryOrderService.getTemOrder(1, 1198803053521391618L, 1067246875800000066L);
        if(null == temOrder){
            temOrder = new TemporaryOrderDTO();
            temOrder.setFlag(0);
        }
        return new Result<TemporaryOrderDTO>().ok(temOrder);
    }
    /**
     * 食材采购订单生成列表
     * @return
     */
    @PostMapping("updeteOrder")
    @ApiOperation("修改草稿列表")
    public Result updeteOrder(@RequestBody TemporaryOrderDTO dto, @LoginUser UserEntity entity){
        System.out.println(dto);
        temporaryOrderService.update(dto);
        return new Result();
    }
    /**
     * 食材采购订单生成列表
     * @return
     */
    @PostMapping("saveOrder")
    @ApiOperation("生成列表")
    public Result saveOrder(@RequestBody TemporaryOrderDTO dto,@LoginUser UserEntity entity){
        dto.setChedId(entity.getId());
        dto.setCanteenId(entity.getDeptId());
        dto.setCreateTime(new Date());
        temporaryOrderService.save(dto);
        return new Result();
    }

}